package 算法语言基础.Day12_7;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;

public class Test15 {
    public static void main(String[] args) {
        HashSet s = new HashSet();
        Scanner scanner = new Scanner(System.in);
        while (true){
            System.out.print("I：插入   S：查询   D：删除   Q：退出   \n请输入你的选项：");
            String select = scanner.next();
            if(select.equals("I")){
                System.out.print("请插入学号：");
                int id = scanner.nextInt();
                System.out.print("请插入姓名：");
                String name = scanner.next();
                System.out.print("请插入电话号码：");
                String phone = scanner.next();
                System.out.print("请插入qq号：");
                int qq = scanner.nextInt();
                Student stu = new Student(id,name,phone,qq);
                s.add(stu);
            }
            else if(select.equals("S")) {
                Iterator i = s.iterator();
                while(i.hasNext()){
                    System.out.println(i.next().toString());
                }
            }
            else if(select.equals("D")) {
                System.out.print("请输入要删除的联系人的学号：");
                int id = scanner.nextInt();
                Iterator i = s.iterator();
                while(i.hasNext()){
                    Student stu = (Student) i.next();
                    if(stu.getId() == id) {
                        s.remove(stu);
                        break;
                    }
                }
            }
            else break;
        }
    }
}
class Student{
    private String name;
    private int id;
    private String phone;
    private int qq;

    public Student(int id, String name, String phone, int qq) {
        this.id = id;
        this.name = name;
        this.phone = phone;
        this.qq = qq;
    }

    public int getId() {
        return id;
    }

    @Override
    public String toString() {
        return "姓名：" + name  +
                ", 学号：" + id +
                ", 手机号：" + phone  +
                ", qq：" + qq;
    }
}
